<template>
  <div class="box">
    <!-- 骨架屏 -->
    <el-skeleton v-if="loading" class="skeleton" animated>
      <template #template>
        <div class="avatar-skeleton" />
        <el-skeleton-item variant="p" class="title-skeleton" />
        <el-skeleton-item variant="text" class="row-skeleton" />
        <el-skeleton-item variant="text" class="row-skeleton" />
        <el-skeleton-item variant="text" class="row-skeleton" />
        <el-skeleton-item variant="text" class="row-skeleton" />
      </template>
    </el-skeleton>

    <!-- 真实内容 -->
    <div v-else class="content">
      <img class="avatar" :src="avatar" alt="avatar" />
      <h1 class="report-title">{{ jur.userName || '—' }}</h1>
      <!-- <el-button type="primary" size="small" @click="toPage('/index')">
        返回首页
      </el-button> -->

      <table class="report-table">
        <tbody>
          <tr>
            <td class="label">姓名</td>
            <td class="value">#{{ jur.userName || '—' }}</td>
          </tr>
          <tr>
            <td class="label">性别</td>
            <td class="value">{{ jur.sex == '0' ? '男' : '女' }}</td>
          </tr>
          <tr>
            <td class="label">状态</td>
            <td class="value">{{ jur.status == '0' ? '正常' : '不正常' }}</td>
          </tr>
          <tr>
            <td class="label">最近登录</td>
            <td class="value">{{ jur.loginDate || '—' }}</td>
          </tr>
          <tr>
            <td class="label">IP</td>
            <td class="value">{{ ip || '—' }}</td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script setup lang="ts">
import { jurisdiction } from '@/store'
import { GetIp } from '@/service/api/map'

const jur = jurisdiction()
const loading = ref(true)
const ip = ref('')

const avatar = new URL('@/assets/img/people/111.jpg', import.meta.url).href

onMounted(async () => {
  try {
    ip.value = (await GetIp()) || ''
  } finally {
    loading.value = false
  }
})
</script>

<style lang="less" scoped>
.box {
  width: 220px;
  position: fixed;
  top: 70px;
  right: 8%;
  background: rgba(5, 62, 69);
  z-index: 10;
  overflow-y: auto;
  /* 内容超出滚动 */
  display: flex;
  /* 垂直居中骨架屏 */
  flex-direction: column;
  border-radius: 0.1rem;
  box-shadow: 0 0 0 1px #429ea5;
}

/* 骨架屏专用 */
.skeleton {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.avatar-skeleton {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  margin-bottom: 12px;
}

.title-skeleton {
  width: 100px;
  height: 18px;
  margin-bottom: 8px;
}

.row-skeleton {
  width: 90%;
  height: 16px;
  margin: 6px 0;
}

/* 真实内容 */
.content {
  width: 100%;
  padding: 12px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.avatar {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  margin-bottom: 8px;
}

.report-title {
  font-size: 16px;
  font-weight: bold;
  color: #fff;
  margin: 4px 0 8px;
}

.el-button {
  margin-bottom: 12px;
  width: 90px;
  font-size: 12px;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  color: #fff;
}

.report-table tr {
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.report-table .label,
.report-table .value {
  padding: 6px 4px;
  line-height: 1.4;
}

.report-table .label {
  width: 50px;
  text-align: justify;
  text-align-last: justify;
  font-weight: bold;
}

.report-table .value {
  text-align: left;
  padding-left: 6px;
}

/* 滚动条美化（可选） */
.box::-webkit-scrollbar {
  width: 4px;
}

.box::-webkit-scrollbar-thumb {
  background: #429ea5;
  border-radius: 2px;
}
</style>